package com.kitchen.ui.dialog.com
{
	import com.kitchen.ui.controls.account.NumberItem;
	
	import flash.display.BitmapData;
	import flash.display.Sprite;

	public class CoinItem extends Sprite
	{
		private var dialogSkin:BitmapData;
		private var mainSkin:BitmapData;
		private var coin:int = 0;
		private var numArray:Array;
		
		public function CoinItem(dialogSkin:BitmapData, mainSkin:BitmapData, coin:int)
		{
			super();
			this.dialogSkin = dialogSkin;
			this.mainSkin = mainSkin;
			this.coin = coin;
			this.numArray = new Array();
			this.layout();
		}
		
		private function layout():void{
			var bg:RectangleIcon = new RectangleIcon(this.dialogSkin);
			this.addChild(bg);
			var coin:CoinIcon = new CoinIcon(this.dialogSkin);
			coin.x = 155;
			coin.y = 3;
			this.addChild(coin);
			this.addNumbers();
		}
		
		private function addNumbers():void{
			var numStr:String = this.coin.toString();
			var offx:int = 145-(numStr.length*11);
			for(var i:int=0; i<numStr.length; i++){
				var num:int = int(numStr.substr(i,1));
				if(this.numArray[i] == null){
					var numItem:NumberItem = new NumberItem(num, this.mainSkin, NumberItem.N_RED);
					numItem.x = offx+i*11;
					numItem.y = 5;
					this.addChild(numItem);
					this.numArray[i]=numItem;
				}else{
					NumberItem(this.numArray[i]).show(num);
				}
			}
		}
		
		public function show(coin:int):void{
			this.coin = coin;
			this.addNumbers();
		}
	}
}